#pragma once
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>

#include "Course.h"

using namespace std;

class Student
{	
private:
	string firstName;
	string secondName;
	int enrollmentYear;
	vector<Course> v;
public:

#pragma region Constructor/Destructor
	Student()
	{
		firstName = secondName = "";
		enrollmentYear = -1;
	}

	Student(string firstName, string secondName, int enrollmentYear)
	{
		this->firstName = firstName;
		this->secondName = secondName;
		this->enrollmentYear = enrollmentYear;
	}

	~Student() {}
#pragma endregion

#pragma region GET/SET
	void setFirstName(string firstName){ this->firstName = firstName; }
	void setSecondName(string secondName){ this->secondName = secondName; }
	void setEnrollmentYear(int enrollmentYear){ this->enrollmentYear = enrollmentYear; }

	string getFirstName(){ return firstName; }
	string getSecondName(){ return secondName; }
	int getEnrollmentYear(){ return enrollmentYear; }
#pragma endregion

#pragma region Read/Write
	void read()
	{
		cout << "First name: ";
		getline(cin, firstName);
		cout << "Second name: ";
		getline(cin, secondName);
		cout << "Enrollment year: ";
		cin >> enrollmentYear;
	}

	void write()
	{
		cout << secondName << ", " << firstName << " enrolled: " << enrollmentYear << endl;
	}
#pragma endregion

#pragma region OperatorOverloading

	//Data format object=(*data*)
	//Student=(Kalle,Anka,1991)
	//Course=(courseName,Year)
	//Result=(testName,grade)
	//Result=(testName,grade)
	friend ostream& operator<<(ostream &out, const Student &s)
	{
		out << "(";
		out << s.firstName << ",";
		out << s.secondName << ",";
		out << s.enrollmentYear << ")";
		return out;
	}

	friend istream& operator>>(istream &in, Student &s)
	{
		string str;
		getline(in, str, '(');
		getline(in, s.firstName, ',');
		getline(in, s.secondName, ',');
		getline(in, str, ')');
		istringstream iss(str);
		iss >> s.enrollmentYear;
		return in;
	}
#pragma endregion

	void addCourse(Course c)
	{
		v.push_back(c);
	}

	void listCourses()
	{
		for (int i = 0; i < v.size(); i++)
		{
			cout << "id " << i << ": " << v[i] << endl;
		}
	}

	void addResult(int courseId, Result r)
	{
		v[courseId].addResult(r);
	}

	void addResultToLatest(Result r)
	{
		v[v.size() - 1].addResult(r);
	}

	string printCourses()
	{
		ostringstream oss;
		for (auto c : v)
		{
			oss << "Course=" << c << endl;
			oss << c.printResults();
		}
		return oss.str();
	}
};

